const express = require('express');
const router = express.Router();
const InboundController = require('../controllers/inboundController');

/**
 * @swagger
 * tags:
 *   name: Inbound
 *   description: 入库管理
 */

/**
 * @swagger
 * /api/inbound:
 *   get:
 *     summary: 获取所有入库单据
 *     tags: [Inbound]
 *     responses:
 *       200:
 *         description: 成功获取入库单据列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   type: array
 *                   items:
 *                     $ref: '#/components/schemas/InboundDocument'
 *       500:
 *         description: 服务器错误
 */
router.get('/', InboundController.getAllInboundDocuments);

/**
 * @swagger
 * /api/inbound/{id}:
 *   get:
 *     summary: 根据ID获取入库单据
 *     tags: [Inbound]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 入库单据ID
 *     responses:
 *       200:
 *         description: 成功获取入库单据
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   $ref: '#/components/schemas/InboundDocument'
 *       404:
 *         description: 入库单据未找到
 *       500:
 *         description: 服务器错误
 */
router.get('/:id', InboundController.getInboundDocumentById);

/**
 * @swagger
 * /api/inbound:
 *   post:
 *     summary: 创建新入库单据
 *     tags: [Inbound]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - goods_id
 *               - supplier
 *               - quantity
 *             properties:
 *               goods_id:
 *                 type: integer
 *                 description: 货物ID
 *               supplier:
 *                 type: string
 *                 description: 供应商
 *               quantity:
 *                 type: integer
 *                 description: 数量
 *               expected_arrival_date:
 *                 type: string
 *                 format: date
 *                 description: 预计到达日期
 *               actual_arrival_date:
 *                 type: string
 *                 format: date
 *                 description: 实际到达日期
 *               status:
 *                 type: string
 *                 description: 状态
 *               operator:
 *                 type: string
 *                 description: 操作员
 *               notes:
 *                 type: string
 *                 description: 备注
 *     responses:
 *       201:
 *         description: 入库单据创建成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *                 data:
 *                   $ref: '#/components/schemas/InboundDocument'
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器错误
 */
router.post('/', InboundController.createInboundDocument);

/**
 * @swagger
 * /api/inbound/{id}/status:
 *   put:
 *     summary: 更新入库单据状态
 *     tags: [Inbound]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 入库单据ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - status
 *             properties:
 *               status:
 *                 type: string
 *                 description: 状态
 *     responses:
 *       200:
 *         description: 入库单据状态更新成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *       400:
 *         description: 请求参数错误
 *       404:
 *         description: 入库单据未找到
 *       500:
 *         description: 服务器错误
 */
router.put('/:id/status', InboundController.updateInboundDocumentStatus);

/**
 * @swagger
 * /api/inbound/{id}/cancel:
 *   put:
 *     summary: 取消入库单据
 *     tags: [Inbound]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 入库单据ID
 *     responses:
 *       200:
 *         description: 入库单据取消成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *       404:
 *         description: 入库单据未找到
 *       500:
 *         description: 服务器错误
 */
router.put('/:id/cancel', InboundController.cancelInboundDocument);

module.exports = router;